home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- # MPing 1.1 - MacTCP Ping Tool
- #
- # Copyright © Apple Computer, Inc. 1990-1991
- # All rights reserved.
- #
- # Versions:
- # 1.1 September 25, 1991.
- #
- # File:
- # MPing.c
- #
- # Components:
- # AddressXlation.h
- # MacTCPCommonTypes.h
- # Makefile
- # MiscIPPB.h
- # MPing.c
- # MPing.h
- # MPing.r
- # MPingDlg.c
- # MPingExtern.h
- # MPingGlobals.h
- # MPingIcmp.c
- # MPingWindow.c
- # resolver.c
- ------------------------------------------------------------------------------*/
-
- #include <Values.h>
- #include <Types.h>
- #include <Resources.h>
- #include <QuickDraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <Desk.h>
- #include <ToolUtils.h>
- #include <Memory.h>
- #include <SegLoad.h>
- #include <Files.h>
- #include <OSUtils.h>
- #include <OSEvents.h>
- #include <DiskInit.h>
- #include <Packages.h>
- #include <Traps.h>
-
- #include "MacTCPCommonTypes.h"
- #include "MPing.h" /* bring in all the #defines for MPing */
- #include "MPingGlobals.h" /* bring in some structure definitions */
- #include "MPingExtern.h" /* all extern variables */
-
-
- void AdjustHV(Boolean isVert, ControlHandle control, TEHandle docTE, Boolean canRedraw);
- void AdjustScrollValues(WindowPtr window, Boolean canRedraw);
- pascal void VActionProc(ControlHandle control, short part);
- void CommonAction(ControlHandle control, short *amount);
- void AdjustScrollbars(WindowPtr window, Boolean needsResize);
- void AdjustScrollSizes(WindowPtr window);
- void GetTERect(WindowPtr window, Rect *teRect);
- void AdjustViewRect(TEHandle docTE);
- void AdjustTE(WindowPtr window);
-
-
- /* Simply call the common adjust routine for the vertical and horizontal scrollbars. */
-
- #pragma segment Window
- void AdjustScrollValues(window, canRedraw)
- WindowPtr window;
- Boolean canRedraw;
- {
- DocumentPeek doc;
-
- doc = (DocumentPeek) window;
- AdjustHV(true, doc->docVScroll, doc->docTE, canRedraw);
- } /*AdjustScrollValues*/
-
-
- /* Calculate the new control maximum value and current value, whether it is the horizontal or
- vertical scrollbar. The vertical max is calculated by comparing the number of lines to the
- vertical size of the viewRect. The horizontal max is calculated by comparing the maximum document
- width to the width of the viewRect. The current values are set by comparing the offset between
- the view and destination rects. If necessary and we canRedraw, have the control be re-drawn by
- calling ShowControl. */
-
- #pragma segment Main
- void AdjustHV(isVert, control, docTE, canRedraw)
- Boolean isVert;
- ControlHandle control;
- TEHandle docTE;
- Boolean canRedraw;
- {
- short value, lines, max;
- short oldValue, oldMax;
- TEPtr te;
-
- oldValue = GetCtlValue(control);
- oldMax = GetCtlMax(control);
- te = *docTE; /* point to TERec for convenience */
- if ( isVert ) {
- lines = te->nLines;
- /* since nLines isn’t right if the last character is a return, check for that case */
- if ( *(*te->hText + te->teLength - 1) == kCrChar )
- lines += 1;
- max = lines - ((te->viewRect.bottom - te->viewRect.top) /
- te->lineHeight);
- } else
- max = kMaxDocWidth - (te->viewRect.right - te->viewRect.left);
-
- if ( max < 0 ) max = 0;
- SetCtlMax(control, max);
-
- /* Must deref. after SetCtlMax since, technically, it could draw and therefore move
- memory. This is why we don’t just do it once at the beginning. */
- te = *docTE;
- if ( isVert )
- value = (te->viewRect.top - te->destRect.top) / te->lineHeight;
- else
- value = te->viewRect.left - te->destRect.left;
-
- if ( value < 0 ) value = 0;
- else if ( value > max ) value = max;
-
- SetCtlValue(control, value);
- /* now redraw the control if it needs to be and can be */
- if ( canRedraw || (max != oldMax) || (value != oldValue) )
- ShowControl(control);
- } /*AdjustHV*/
-
- /* Determines how much to change the value of the vertical scrollbar by and how
- much to scroll the TE record. */
-
- #pragma segment Main
- pascal void VActionProc(control,part)
- ControlHandle control;
- short part;
- {
- short amount;
- WindowPtr window;
- TEPtr te;
-
- if ( part != 0 ) { /* if it was actually in the control */
- window = (*control)->contrlOwner;
- te = *((DocumentPeek) window)->docTE;
- switch ( part ) {
- case inUpButton:
- case inDownButton: /* one line */
- amount = 1;
- break;
- case inPageUp: /* one page */
- case inPageDown:
- amount = (te->viewRect.bottom - te->viewRect.top) / te->lineHeight;
- break;
- }
- if ( (part == inDownButton) || (part == inPageDown) )
- amount = -amount; /* reverse direction for a downer */
- CommonAction(control, &amount);
- if ( amount != 0 )
- TEScroll(0, amount * te->lineHeight, ((DocumentPeek) window)->docTE);
- }
- } /* VActionProc */
-
- /* Common algorithm for pinning the value of a control. It returns the actual amount
- the value of the control changed. Note the pinning is done for the sake of returning
- the amount the control value changed. */
-
- #pragma segment Main
- void CommonAction(control,amount)
- ControlHandle control;
- short *amount;
- {
- short value, max;
-
- value = GetCtlValue(control); /* get current value */
- max = GetCtlMax(control); /* and maximum value */
- *amount = value - *amount;
- if ( *amount < 0 )
- *amount = 0;
- else if ( *amount > max )
- *amount = max;
- SetCtlValue(control, *amount);
- *amount = value - *amount; /* calculate the real change */
- } /* CommonAction */
-
-
- /* Turn off the controls by jamming a zero into their contrlVis fields (HideControl erases them
- and we don't want that). If the controls are to be resized as well, call the procedure to do that,
- then call the procedure to adjust the maximum and current values. Finally re-enable the controls
- by jamming a $FF in their contrlVis fields. */
-
- #pragma segment Main
- void AdjustScrollbars(window, needsResize)
- WindowPtr window;
- Boolean needsResize;
- {
- DocumentPeek doc;
-
- doc = (DocumentPeek) window;
- /* First, turn visibility of scrollbars off so we won’t get unwanted redrawing */
- (*doc->docVScroll)->contrlVis = kControlInvisible; /* turn them off */
- if ( needsResize ) /* move & size as needed */
- AdjustScrollSizes(window);
- AdjustScrollValues(window, needsResize); /* fool with max and current value */
- /* Now, restore visibility in case we never had to ShowControl during adjustment */
- (*doc->docVScroll)->contrlVis = kControlVisible; /* turn them on */
- } /* AdjustScrollbars */
-
- /* Re-calculate the position and size of the viewRect and the scrollbars.
- kScrollTweek compensates for off-by-one requirements of the scrollbars
- to have borders coincide with the growbox. */
-
- #pragma segment Main
- void AdjustScrollSizes(window)
- WindowPtr window;
- {
- Rect teRect;
- DocumentPeek doc;
-
- doc = (DocumentPeek) window;
- GetTERect(window, &teRect); /* start with TERect */
- (*doc->docTE)->viewRect = teRect;
- AdjustViewRect(doc->docTE); /* snap to nearest line */
- } /*AdjustScrollSizes*/
-
- #pragma segment Main
- void GetTERect(window, teRect)
- WindowPtr window;
- Rect *teRect;
- {
- *teRect = gMsgRect;
- InsetRect(teRect, kTextMargin, kTextMargin);
- teRect->right = teRect->right - 15; /* for the vertical scrollbar */
- }
-
- #pragma segment Main
- void AdjustViewRect(docTE)
- TEHandle docTE;
- {
- TEPtr te;
-
- te = *docTE;
- te->viewRect.bottom = (((te->viewRect.bottom - te->viewRect.top) / te->lineHeight)
- * te->lineHeight) + te->viewRect.top;
- } /*AdjustViewRect*/
-
- /* Scroll the TERec around to match up to the potentially updated scrollbar
- values. This is really useful when the window has been resized such that the
- scrollbars became inactive but the TERec was already scrolled. */
-
- #pragma segment Main
- void AdjustTE(window)
- WindowPtr window;
- {
- TEPtr te;
-
- te = *((DocumentPeek)window)->docTE;
- TEScroll(0, (te->viewRect.top - te->destRect.top) -
- (GetCtlValue(((DocumentPeek)window)->docVScroll) * te->lineHeight),
- ((DocumentPeek)window)->docTE);
- } /*AdjustTE*/
-